package com.sinodoggo.shitcloud.exception;

import com.sinodoggo.shitcloud.commons.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * #Author :Sino
 * #Date   :2022/11/20 17:29
 * #Describe:
 */
// @ControllerAdvice是一个为控制器增强的注解
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    //处理自定义异常
    @ExceptionHandler(ServiceException.class)
    public Result errorMyExceptionHandler(ServiceException serviceException){
        return Result.fail(serviceException.getCode(), serviceException.getMessage());
    }
}
